package day14.problem3;

import java.util.Scanner;

//删除相邻数字的最大分数(打家劫舍改编)
//https://www.nowcoder.com/practice/3bcf72c738b6494bbe1ebe0ffde56152?tpId=230&tqId=40419&ru=/exam/oj

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        final int M = 10003;
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int[] sum = new int[M]; //sum[i]:数字i出现的总和
        for(int i = 0; i<n; i++) {
            arr[i] = in.nextInt();
            sum[arr[i]] += arr[i];
        }
        int[] f = new int[M]; //0~i直接的最大和, 包括i
        int[] g = new int[M]; //0~i直接的最大和, 不包括i
        
        for(int i = 1; i<M; i++) {
            f[i] = g[i-1] + sum[i];
            g[i] = Math.max(g[i-1], f[i-1]);
        }

        int ret = Math.max(f[M-1], g[M-1]);
        System.out.println(ret);
    }
}